<?php

$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'核销记录'),
);
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('isuse'=>1,'ordersn'=>'hexiao','uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params2=array('uniacid'=>$_SESSION['uniacid']);
		$params2['title like']='%'.trim($_RQ['title']).'%';
		$couponids=pdo_getall('jy_weishop_coupon',$params2,'id','id');
		$couponids=$couponids?array_keys($couponids):-1;
		$params['couponid']=$couponids;
		$return['params']['title']=$_RQ['title'];
	}
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	//创建时间
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
		$return['params']['createtime']=$time_range;
	}
    $fields=array();
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_weishop_coupon_getlog',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$return['gettype']=array('1'=>'后台发放','2'=>'自己领取');
	foreach($return['list'] as &$v){
		$v['createtime']=$v['createtime']?date('Y/m/d H:i:s',$v['createtime']):'--';
		$v['usetime']=$v['usetime']?date('Y/m/d H:i:s',$v['usetime']):'--';
		$v['member']=cfc('core')->member_show($v['mid']);
		$v['title']=pdo_getcolumn('jy_weishop_coupon',array('id'=>$v['couponid']),'title');
	}
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'title','title'=>'优惠券名称','type'=>'string'),
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'gettype','title'=>'获得方式','type'=>'radio','options'=>'gettype'),
			array('name'=>'createtime','title'=>'获得时间','type'=>'string'),
			array('name'=>'usetime','title'=>'核销时间','type'=>'string'),		
		)),
		'search'=>array(
			array('name'=>'title','width'=>13,'title'=>'优惠券名称','type'=>'string'),
			array('type'=>'choose','width'=>13,'title'=>'所属会员ID','name'=>'mid','action'=>'core/member.get_member/'),
			array('name'=>'createtime','width'=>15,'title'=>'获得时间','type'=>'time_range'),
		)
	);
	$return['htmls']=$htmls;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	exi($return);
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_weishop_coupon_getlog',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_weishop_coupon_getlog',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}	

?>